<?php if (!defined('THINK_PATH')) exit(); /*a:2:{s:55:"D:\www\tp7./application/houtai\view\database\index.html";i:1503648760;s:54:"D:\www\tp7./application/houtai\view\public\header.html";i:1504938710;}*/ ?>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="renderer" content="webkit">
<title>樱桃的站点后台管理系统</title>  
<link rel="shortcut icon" href="__INDEX__/images/favicon.ico">
<link rel="stylesheet" href="__HOUTAI__/css/pintuer.css">
<link rel="stylesheet" href="__HOUTAI__/css/admin.css">

<script src="__HOUTAI__/js/jquery-2.1.4.min.js"></script>
<script src="__HOUTAI__/js/layer.js"></script>


<script src="__HOUTAI__/js/jquery.validate.js"></script>
<script src="__HOUTAI__/js/additional-methods.js"></script>
<script src="__HOUTAI__/js/messages_zh.js"></script>
<!-- 字体图标文件CSS -->
<link rel="stylesheet" type="text/css" href="//at.alicdn.com/t/font_394272_s1c3jukr7t10dx6r.css">
<!-- 字体图标文件js -->
<script type="text/javascript" src="//at.alicdn.com/t/font_394272_s1c3jukr7t10dx6r.js"></script>


<!-- <script type="text/javascript" src="http://malsup.github.io/jquery.form.js"></script> -->

</head>
<body>
<div class="panel admin-panel">
<div class="panel-head"><strong class="icon-menu"> 数据库备份</strong></div>

<form method="post" id="export-form" action="<?php echo url('database/export'); ?>">
<div class="padding border-bottom">
  <ul class="search" style="padding-left:10px;">
    <li> <a class="button border-main " id="export" href="javascript:;"><i class="icon-c-databackup"></i> 立即备份</a> </li>
    <li><a id="optimize" href="<?php echo url('database/optimize'); ?>" class="button border-green"><span class="icon-12001"></span> 优化表</a></li>
    <li><a id="repair" class="button border-green" href="<?php echo url('database/repair'); ?>"><span class="icon-zidongxiufu"></span> 修复表</a></li>
  </ul>
</div>
    <table class="table table-hover text-center">
      <tr>
        <td width="20"><label><input class="check-all" checked="chedked" type="checkbox" value=""></label></td>
        <td width="150" align="center">表名</td>
        <td width="120" align="center">数据量</td>
        <td width="120" align="center">数据大小</td>
        <td width="150" align="center">创建时间</td>
        <td width="150" align="center">说明</td>
        <td width="150" align="center">备份状态</td>
      </tr>
      <?php if(is_array($_list) || $_list instanceof \think\Collection || $_list instanceof \think\Paginator): $i = 0; $__LIST__ = $_list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$table): $mod = ($i % 2 );++$i;?>
      <tr>
        <td width="20"><input class="ids" checked="chedked" type="checkbox" name="tables[]" value="<?php echo $table['name']; ?>"></td>
        <td width="150" align="center"><?php echo $table['name']; ?></td>
        <td width="120" align="center"><?php echo $table['rows']; ?></td>
        <td width="120" align="center"><?php echo format_bytes($table['data_length']); ?></td>
        <td width="150" align="center"><?php echo $table['create_time']; ?></td>
        <td width="150" align="center"><?php echo $table['comment']; ?></td>
        <td width="150" align="center" class="info">未备份</td>
      </tr>
      <?php endforeach; endif; else: echo "" ;endif; ?>
      <tr>
      </tr>
    </table>
  </div>
</form>
<script>
$(function(){
  var $form = $("#export-form"), tables
      $export = $("#export"), 
      $optimize = $("#optimize"), 
      $repair = $("#repair");

      $optimize.add($repair).click(function(){
        $.post(this.href, $form.serialize(), function(data){
          if(data.code){
              layer.msg(data.msg, {icon: 1});
          } else {
              layer.msg(data.msg, {icon: 5});
          }
        }, "json");
        return false;
      });

      $export.click(function(){
        $export.parent().children().addClass("disabled");
        $export.html("<i class='icon-feiji'></i> 正在发送备份请求...");
        $.post(
            $form.attr("action"),
            $form.serialize(),
            function(data){
                if(data.code){
                    tables = data.data.tables;
                    $export.html(data.msg + "开始备份，请不要关闭本页面！");
                    backup(data.data.tab);
                    window.onbeforeunload = function(){ return "正在备份数据库，请不要关闭！" }
                } else {
                    layer.msg(data.msg, {icon: 5});
                    $export.parent().children().removeClass("disabled");
                    $export.html("立即备份");
                }
            },
            "json"
        );
        return false;
      });

        function backup(tab, code){
            code && showmsg(tab.id, "开始备份...(0%)");
            $.get($form.attr("action"), tab, function(data){
                if(data.code){
                    showmsg(tab.id, data.msg);
                    if(!$.isPlainObject(data.data.tab)){
                        $export.parent().children().removeClass("disabled");
                        $export.html("<i class='icon-iconfontwancheng'></i> 备份完成，点击重新备份");
                        window.onbeforeunload = function(){ return null }
                        return;
                    }
                    backup(data.data.tab, tab.id != data.data.tab.id);
                } else {
                    layer.msg(data.msg, {icon: 5});
                    $export.parent().children().removeClass("disabled");
                    $export.html("立即备份");
                }
            }, "json");

        }

        function showmsg(id, msg){
            $form.find("input[value=" + tables[id] + "]").closest("tr").find(".info").html(msg);
        }
});
</script>
</body>
</html>